<?php $this->load->view('include/navbar');?>

  <div class="row">
     <div class="span12">
       <h2>Welcome <?php echo $username; ?>!</h2>

        <ul class="breadcrumb">
          <li><a href="home/logout">Logout</a></li>
        </ul>

      <table class="table table-striped" id='result_table'></table>

    </div>   
  </div>
<script type='text/javascript' language='javascript'>
function get_users(){
      $.ajax({
          url: '<?php echo base_url();?>index.php/home/list_online',
          data:'',
          dataType: 'json',
          success: function(data){
            for(var x=0; x < data.length; x++){    
              
              if(data.length == 0){                   
                $('#result_table')[0].innerHTML = 
                  '<th>No Online Found</th>'; 
              }         
              else{
                $('#result_table')[0].innerHTML = 
                  '<th>Username</th>' +
                  '<th id="stat">Online</th>';
       
                    for(var x=0; x < data.length; x++)
                    { 
                      $('#result_table')[0].innerHTML += 
                        '<tr>' +
                          '<td>' +
                               data[x]['username'] +
                             
                          '</td>' +
                          '<td>' +
                            '<a href=#>Challenge</a>'+ 
                          '</td>' +
                        '</tr>';    
                                          
                    }
                }
               
              }
                 
          } // End of success function of ajax form
      }); // End of ajax call
}

  $(document).ready(function()
    {

    $.ajaxSetup({ cache: false }); 
    setInterval(function(){
    get_users();
    
    }, 1000); // end of setInterval  
    });
  
</script>


 